package com.xhui.vimarket.zkplus.zul.attr.evt;

import org.zkoss.zk.ui.Component;
import org.zkoss.zul.Hbox;
import org.zkoss.zul.Textbox;

/**
 * 清空按钮.
 * 
 * @author wuyx
 * @version Revision 1.0.0
 * 
 */
public class AttrButtonTextRefreshBtnComposer extends AttrBaseComposer {
    
    /**
     * .
     */
    private static final long serialVersionUID = 1L;
    
    @Override
    public void doAfterCompose(final Component comp) throws Exception {
        super.doAfterCompose(comp);
        this.init(comp);
    }
    
    /**
     * init.
     * @param comp  Component
     */
    public void init(final Component comp) {
        if (comp.getParent() != null && comp.getParent().getParent() != null) {
            if (comp.getParent().getParent() instanceof Hbox
                && comp.getParent().getParent().hasAttribute(
                    AttrButtonTextBtnComposer.TAG_HIDE_RESET_BTN)) {
                comp.setVisible(false);
            }
        }
    }
    
    /**
     * onClick.
     */
    public void onClick() {
        final Component hbox = this.self.getParent().getParent();
        if (hbox != null) {
            final Textbox textbox = (Textbox) hbox.getLastChild().getFirstChild();
            if (textbox != null) {
                textbox.setValue("");
                textbox.removeAttribute(AttrButtonTextComp.TAG_VALUE_ID);
                textbox.removeAttribute(AttrButtonTextComp.TAG_VALUE_OBJECT);
            }
        }
    }
    
}
